package teamproject.visualization.gui;

import javax.media.j3d.Alpha;
import javax.media.j3d.Bounds;
import javax.media.j3d.PositionPathInterpolator;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

/**
 * Creates a TransformGroup object that moves a Shape3D object along a certain
 * path.
 */
public class PackageMover implements TransformGroupGenerator {

	private TransformGroup tg;
	private Bounds bounds;
	private Alpha alpha;
	private float[] knots;
	private Point3f[] positions;

	public PackageMover(Bounds bounds, Alpha alpha, float[] knots,
			Point3f[] positions) {
		this.bounds = bounds;
		this.alpha = alpha;
		this.knots = knots;
		this.positions = positions;
		tg = new TransformGroup();
	}

	@Override
	public TransformGroup getTransformGroup() {
		tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		Transform3D axis = new Transform3D();
		Vector3f localCoordinate = new Vector3f(0.0f, 0.0f, 0.0f);
		axis.set(localCoordinate);

		PositionPathInterpolator interpolator = new PositionPathInterpolator(
				alpha, tg, axis, knots, positions);
		interpolator.setBounds(bounds);

		tg.addChild(interpolator);

		return tg;
	}
}
